lexer grammar AnalizadorXml;

options {
  language = Java;
}

@lexer::header{package PL.practica4vs2;}

@lexer::members {
public class MyToken extends CommonToken {
    String nFile; // custom field
    public MyToken(CharStream input, int type, int channel, int start, int stop){
        super(input, type, channel, start, stop);
        nFile = "";
    }
    public void getNfile (String s){nFile= s;}
    public String setNfile (){return nFile;}
    public String toString() { return super.toString()+",nombre fichero="+nFile; }
}
ArrayList <RecognitionException> errores = new ArrayList<RecognitionException>();

public boolean listaVacia (){
    if (errores.isEmpty()){
      return true;
    }else
      return false;
}

public ArrayList getListaErrores(){return errores;}

@Override
public void reportError (RecognitionException e){
  errores.add(e);
}
 
// override standard token emission
public Token emit() {
    MyToken t =
        new MyToken(input, state.type, state.channel,
                    state.tokenStartCharIndex, getCharIndex()-1);
    t.setLine(state.tokenStartLine);
    t.setText(state.text);
    t.setCharPositionInLine(state.tokenStartCharPositionInLine);
    t.nFile = this.getSourceName();
    emit(t);
    return t;
}
}
 
 
  fragment NUEVA_LINEA: '\r\n';
  fragment DIGITO: '0'..'9';
  fragment LETRA : ('a'..'z')|('A'..'Z')|'_';
  BLANCO: (' '|'\t'|NUEVA_LINEA) {skip();};
  BIBLIO : 'biblioteca';
  LIB : 'libro';
  TIT: 'titulo';
  AUT : 'autor';
  EDIT : 'editorial';
  NUMERO: (DIGITO)+('.'(DIGITO)+)?;
  OPERADOR: '+'|'-'|'/'|'*';
  PARENTESIS: '('|')';
  SEPARADOR: ';';
  SIMBOLOS : '&'|'.';
  COMENTARIO: '<!--' (options {greedy=false;}:.)* '-->' {skip();};
      PALABRA: LETRA(LETRA|DIGITO)*;
  //ETIQUETAINI: '<' (options {greedy=false;}:.)* '>';
  //ETIQUETAFIN:  '</' (options {greedy=false;}:.)* '>';
  ETIQUETAINI: '<' (BIBLIO |LIB| TIT| AUT| EDIT) '>';
  ETIQUETAFIN: '</' (BIBLIO |LIB| TIT| AUT| EDIT) '>';
  